import jQuery from 'jquery'
import 'popper.js'
import 'bootstrap'

import http from 'axios'


function getQuery(key) {
  let arr = location.search.slice(1).split('&')
  for (let item of arr) {
    let item_temp = item.split('=')

    if (item_temp[0] === key) {
      return item_temp[1]
    }
  }
}


http({
  url: `https://gank.io/api/v2/post/${getQuery('id')}`
}).then(res => {
  console.log(res.data)
  const { images = 'http://gank.io/images/d6bba8cf5b8c40f9ad229844475e9149', desc, title } = res.data.data
  console.log(images)
  console.log(desc)
  console.log(title)
  jQuery(`
       <div class="text-center">
      <div class="card">
        <img src="${images[0]}" class="card-img-top" alt="...">
        <div class="card-body">
          <h5 class="card-title">${title}</h5>
          <p class="card-text">${desc}</p>
        </div>
      </div>
    </div>`).appendTo('.box')

}).catch(e => {
  console.log(e)
}).finally(() => {
  console.log('ok!')
})







